package xyz.coolcsm.security.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.coolcsm.security.entity.SysPermission;
import xyz.coolcsm.security.mapper.SysPermissionMapper;
import xyz.coolcsm.security.service.SysPermissionService;

import java.util.List;
/**
 * @author 什锦
 * @since 2021-06-1
 */
@Service
public class SysPermissionServiceImpl implements SysPermissionService {

    @Autowired
    private SysPermissionMapper sysPermissionMapper;

    @Override
    public List<SysPermission> selectListByUser(Integer userId) {
        return sysPermissionMapper.selectListByUser(userId);
    }

    @Override
    public List<SysPermission> queryAllByLimit(int offset, int limit) {
        Page<SysPermission> page = new Page<>(offset,limit);
        Page<SysPermission> result = sysPermissionMapper.selectPage(page, null);
        return result.getRecords();
    }

    @Override
    public SysPermission insert(SysPermission sysPermission) {
        sysPermissionMapper.insert(sysPermission);
        return sysPermission;
    }

    @Override
    public SysPermission update(SysPermission sysPermission) {
        sysPermissionMapper.updateById(sysPermission);
        return sysPermission;
    }

    @Override
    public boolean deleteById(Integer id) {
        return sysPermissionMapper.deleteById(id)>0;
    }

    @Override
    public List<SysPermission> selectListByPath(String path) {
        return sysPermissionMapper.selectListByPath(path);
    }
}
